package cn.cyh.user.controller;

import cn.cyh.Dto.LoginDto;
import cn.cyh.basic.exception.BusinessException;
import cn.cyh.basic.uitls.AJaxResult;
import cn.cyh.user.service.ILoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@RequestMapping("/login")
public class LoginController {
    @Autowired
    private ILoginService loginService;
    @PostMapping("/account")
    public AJaxResult account(@RequestBody LoginDto loginDto) {
        try {
           Map<String,Object> map =  loginService.accountLogin(loginDto);
            return AJaxResult.myself().setResultObj(map);
        } catch (BusinessException e) {
            e.printStackTrace();
            return AJaxResult.myself().setMsg(e.getMessage());

        } catch (Exception e) {
            e.printStackTrace();
            return AJaxResult.myself().setMsg("系统繁忙");
        }
    }

    @PostMapping("/wechat")
    public AJaxResult account(@RequestBody Map<String,String> params) {
        try {
          return loginService.wechat(params);
        } catch (BusinessException e) {
            e.printStackTrace();
            return AJaxResult.myself().setMsg(e.getMessage());

        } catch (Exception e) {
            e.printStackTrace();
            return AJaxResult.myself().setMsg("系统繁忙");
        }
    }
    @PostMapping("/binder/wechat")
    public AJaxResult binder(@RequestBody Map<String,String> params) {
        try {
            Map<String,Object> map =  loginService.binder(params);
            return AJaxResult.myself().setResultObj(map);
        } catch (BusinessException e) {
            e.printStackTrace();
            return AJaxResult.myself().setMsg(e.getMessage());

        } catch (Exception e) {
            e.printStackTrace();
            return AJaxResult.myself().setMsg("系统繁忙");
        }
    }
}
